package cn.buk.tms.eotms.controller;

import cn.buk.common.dto.CommonDto;
import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.eotms.dto.ServiceProductDto;
import cn.buk.tms.eotms.entity.TieInProduct;
import cn.buk.tms.eotms.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * value-added service 增值服务
 * TODO 临时从tms代码中复制过来。今后将把从捷西接口对接的部分独立出来。 2020-03-25 yfdai
 * 机场服务，调用接口
 * @author yfdai
 */
@RestController
@RequestMapping("/vas")
public class VasController extends BaseController {

  @Autowired
  private ProductService productService;

  /**
   * 可用的服务产品(保险产品）
   * @param request
   * @return
   */
  @GetMapping("/insurances")
  public CommonDto<ServiceProductDto> searchInsuranceProducts(HttpServletRequest request,
                                                                  @RequestParam("pageNo") int pageNo,
                                                                  @RequestParam("pageSize") int pageSize) {
    final int userId = getUserId(request);

    CommonSearchCriteria sc = new CommonSearchCriteria();
    sc.setPageNo(pageNo);
    sc.setPageSize(pageSize);
    sc.setStatus(1);

    List<ServiceProductDto> list =  productService.searchTieInProducts(userId, TieInProduct.INSURANCE, sc);

    CommonDto<ServiceProductDto> dto = new CommonDto<>();
    dto.setDataList(list);
    dto.setPage(sc.getPage());

    return dto;
  }

}
